package com.axxc.cloud.config;

import java.util.Arrays;
import java.util.Map;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;

/**
 * Http Request 请求监听器
 */
@WebListener
public class HttpRequestListener implements ServletRequestListener {

	@Override
	public void requestDestroyed(ServletRequestEvent sre) {
		HttpServletRequest request = (HttpServletRequest) sre.getServletRequest();
		System.err.println(request.getRemoteAddr());
		System.out.println(this.getClass() + "WebRequestListener 销毁,该次请求结束");
	}

	@Override
	public void requestInitialized(ServletRequestEvent sre) {
		System.out.println(this.getClass() + "WebRequestListener 初始化");
		HttpServletRequest request = (HttpServletRequest) sre.getServletRequest();
		Map<String, String[]> map = request.getParameterMap();

		map.forEach((K, V) -> {
			System.out.println(K);
			System.out.println(Arrays.toString(V));
		});
	}

}
